﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RequestManager : BaseManager
{



	private Dictionary<MethodType, BaseRequest> _requestDict;

	public void AddRequestToDict(MethodType methodType,BaseRequest request)
	{
		_requestDict.Add(methodType,request);
	}
	
	public void RemoveRequestFromDict(MethodType methodType)
	{
		_requestDict.Remove(methodType);
	}
	
	
	
	public override void OnInit()
	{
		_requestDict=new Dictionary<MethodType, BaseRequest>();
	}

	public override void OnUpdate()
	{
		
	}

	public override void OnDestroy()
	{
		
	}


	public void HandleResponse(NettyResponse nettyResponse)
	{
		BaseRequest request = null;
		_requestDict.TryGetValue((MethodType) nettyResponse.methodType,out request);
		if (request != null)
		{
			request.OnResponse(nettyResponse.data);
		}
		else
		{
			Debug.Log("MethodType:"+(MethodType)nettyResponse.methodType+"不存在对应的Request实例");
		}
	}
}
